import {get, set} from '@/api/persistent'
import { DATA_SOURCE_LIST } from '@/consts/Consts'
import {dungeons} from "@/api/data/dungeons";

let dataSourceList = dungeons

export function initDataSource() {
  dataSourceList = persistentGet()
  if (dataSourceList == null) {
    dataSourceList = []
    persistentSet(dataSourceList)
  }
  return dataSourceList
}

export function getDataSourceList() {
  return dataSourceList
}

export function addDataSource(name) {
  if (dataSourceList.indexOf(name) < 0 && name !== '' && name != null) {
    dataSourceList.push(name)
    persistentSet(dataSourceList)
  }
}

export function deleteDataSource(name) {
  const index = dataSourceList.indexOf(name)
  dataSourceList.splice(index, 1)
  persistentSet(dataSourceList)
}


function persistentGet() {
  return get(DATA_SOURCE_LIST)
}

function persistentSet(dataSource) {
  set(DATA_SOURCE_LIST, dataSource)
}
